<template>
  <div class="home-router" v-if="showList.length>0">
    <div class="list">
      <div class="item"
           @click="path_url(item.forwardPath)"
           v-for="(item, index) in showList"
           :key="index">
        <img :src="item.imgUrl" alt="">
        <div class="title">{{ item.title }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      luckyData: [],
      financialData: [],
    }
  },
  created() {
    // this.getConfig('FINANCIAL_MANAGEMENT')
    this.getConfig('financial')
    this.getConfig('Lucky_wheel')
  },
  methods: {
    async getConfig(type) {
      const url = this.URL.home.ads
      const params = {positionKey: type}
      const res = await this.$post(url, params)
      if (res.code == 0) {
        const key = type == 'Lucky_wheel' ? 'luckyData' : 'financialData'
        this[key] = res.data||[];
      }
    },
    path_url(url) {
      if (/^http/.test(url)) {
        return this.common.openUrl(url);
      }
      this.$router.push({path: url});
    }
  },
  computed: {
    showList() {
      let list = []
      const {luckyData, financialData} = this
      const luckyLen = luckyData.length
      const financialLen = financialData.length
      if (luckyLen > 0) {
        if (financialLen > 0) {
          list.push(luckyData[1] || luckyData[0])
          list.push(financialData[0])
        } else {
          list.push(luckyData[0])
        }
      } else {
        if (financialLen > 0) {
          list.push(financialData[0])
        }
      }
      return list
    }
  }
}
</script>

<style lang="less" scoped>
.home-router {
  margin-bottom: .4rem;
  line-height: 1.2;

  .list {
    display: flex;
    align-items: stretch;
    gap: .24rem;

    .item {
      flex: 1;
      position: relative;

      img {
        width: 100%;
        height: 100%;
        min-height: 1.28rem;
        border-radius: .24rem;
      }

      .title {
        position: absolute;
        left: .24rem;
        top: 50%;
        transform: translate(0, -50%);
        color: #FFF;
        font-size: .32rem;
      }
    }
  }
}
</style>